/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Client_GUI.SavingBook;

import Client_GUI.Customer.JP_AddCustomer;
import Client_GUI.Unity;
import Interface.IRemoteCustomer;
import Interface.IRemoteSavingBook;
import Interface.IRemoteSavingType;
import Server.DTO.Customer_DTO;
import Server.DTO.Deposit_DTO;
import Server.DTO.SavingBook_DTO;
import Server.DTO.WithDraw_DTO;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author 10520_000
 */
public class JP_SavingBook extends org.jdesktop.swingx.JXPanel {
    private Registry registry;
    private IRemoteCustomer rcustomer;
    private IRemoteSavingBook rsavingbook;
    private IRemoteSavingType rsavingtype;
    table_SavingBook table = new table_SavingBook();
    /**
     * Creates new foforJP_SavingTypeSavingTypeer    */
    public JP_SavingBook() throws RemoteException, NotBoundException {
        initComponents();
        registry = LocateRegistry.getRegistry("127.0.0.1");
        rcustomer = (IRemoteCustomer) registry.lookup("Customer");
        rsavingbook = (IRemoteSavingBook) registry.lookup("SavingBook");
        rsavingtype = (IRemoteSavingType) registry.lookup("SavingType");
        table.setTable(jTable_Cus);
        LoadTable();
    }
    
    public void ClearAll(){
        this.txt_MaSo.setText("");
        this.txt_KyHan.setText("");
        this.txt_TenLoaiTietKiem.setText("");
        this.txt_TenChuSo.setText("");
        this.txt_SoCMND.setText("");
        this.txt_SoTienTrongTaiKhoan.setText("");
        this.txt_TrangThaiSo.setText("");
        //gan ngay mac dinh
        java.sql.Date date = new java.sql.Date(System.currentTimeMillis());
        SimpleDateFormat dayFormat = new SimpleDateFormat("dd/MM/yyyy");
        JXNgayMoSo.setDate(date);
    }
    
    public void LoadTable() throws RemoteException, NotBoundException{
        this.jTable_Cus.setModel(table.LoadTable());
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jAASLoginService1 = new org.jdesktop.swingx.auth.JAASLoginService();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txt_MaSo = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        txt_TenChuSo = new javax.swing.JTextField();
        txt_SoCMND = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        txt_SoTienTrongTaiKhoan = new javax.swing.JTextField();
        txt_KyHan = new javax.swing.JTextField();
        txt_TenLoaiTietKiem = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        txt_TrangThaiSo = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        JXNgayMoSo = new org.jdesktop.swingx.JXDatePicker();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable_Cus = new javax.swing.JTable();
        btn_Them = new javax.swing.JButton();
        btn_Gui = new javax.swing.JButton();
        btn_Gui1 = new javax.swing.JButton();

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Thông tin khách hàng"));

        jLabel1.setFont(new java.awt.Font("Times New Roman", 0, 15)); // NOI18N
        jLabel1.setText("Mã Sổ");

        txt_MaSo.setFont(new java.awt.Font("Times New Roman", 0, 15)); // NOI18N
        txt_MaSo.setEnabled(false);

        jLabel2.setFont(new java.awt.Font("Times New Roman", 0, 15)); // NOI18N
        jLabel2.setText("Tên Chủ Sổ");

        txt_TenChuSo.setFont(new java.awt.Font("Times New Roman", 0, 15)); // NOI18N

        txt_SoCMND.setFont(new java.awt.Font("Times New Roman", 0, 15)); // NOI18N

        jLabel3.setFont(new java.awt.Font("Times New Roman", 0, 15)); // NOI18N
        jLabel3.setText("Số CMND");

        jLabel4.setFont(new java.awt.Font("Times New Roman", 0, 15)); // NOI18N
        jLabel4.setText("Tên Loại Tiết Kiệm");

        jLabel5.setFont(new java.awt.Font("Times New Roman", 0, 15)); // NOI18N
        jLabel5.setText("Kỳ Hạn");

        jLabel6.setFont(new java.awt.Font("Times New Roman", 0, 15)); // NOI18N
        jLabel6.setText("Số Tiền Trong Tài Khoản");

        txt_SoTienTrongTaiKhoan.setFont(new java.awt.Font("Times New Roman", 0, 15)); // NOI18N

        txt_KyHan.setFont(new java.awt.Font("Times New Roman", 0, 15)); // NOI18N

        txt_TenLoaiTietKiem.setFont(new java.awt.Font("Times New Roman", 0, 15)); // NOI18N

        jLabel7.setFont(new java.awt.Font("Times New Roman", 0, 15)); // NOI18N
        jLabel7.setText("Ngày Mở Sổ");

        txt_TrangThaiSo.setFont(new java.awt.Font("Times New Roman", 0, 15)); // NOI18N

        jLabel8.setFont(new java.awt.Font("Times New Roman", 0, 15)); // NOI18N
        jLabel8.setText("Trạng Thái Sổ");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel7)
                            .addComponent(jLabel8))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2)
                            .addComponent(jLabel4)
                            .addComponent(jLabel5)
                            .addComponent(jLabel3)
                            .addComponent(jLabel6))))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txt_TrangThaiSo, javax.swing.GroupLayout.DEFAULT_SIZE, 205, Short.MAX_VALUE)
                    .addComponent(txt_MaSo, javax.swing.GroupLayout.DEFAULT_SIZE, 205, Short.MAX_VALUE)
                    .addComponent(txt_TenChuSo, javax.swing.GroupLayout.DEFAULT_SIZE, 205, Short.MAX_VALUE)
                    .addComponent(txt_SoCMND, javax.swing.GroupLayout.DEFAULT_SIZE, 205, Short.MAX_VALUE)
                    .addComponent(txt_SoTienTrongTaiKhoan, javax.swing.GroupLayout.DEFAULT_SIZE, 205, Short.MAX_VALUE)
                    .addComponent(txt_TenLoaiTietKiem, javax.swing.GroupLayout.DEFAULT_SIZE, 205, Short.MAX_VALUE)
                    .addComponent(txt_KyHan, javax.swing.GroupLayout.DEFAULT_SIZE, 205, Short.MAX_VALUE)
                    .addComponent(JXNgayMoSo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txt_MaSo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txt_TenChuSo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txt_SoCMND, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(txt_TenLoaiTietKiem, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(txt_KyHan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(txt_SoTienTrongTaiKhoan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txt_TrangThaiSo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 16, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(JXNgayMoSo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        jTable_Cus.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jTable_Cus.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable_CusMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTable_Cus);

        btn_Them.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/32/Small_AddCustomer.png"))); // NOI18N
        btn_Them.setText("Thêm ");
        btn_Them.setToolTipText("");
        btn_Them.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        btn_Them.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btn_Them.setIconTextGap(40);
        btn_Them.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_ThemActionPerformed(evt);
            }
        });

        btn_Gui.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/32/Small_AddCustomer.png"))); // NOI18N
        btn_Gui.setText("Gửi Tiền");
        btn_Gui.setToolTipText("");
        btn_Gui.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        btn_Gui.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btn_Gui.setIconTextGap(40);
        btn_Gui.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_GuiActionPerformed(evt);
            }
        });

        btn_Gui1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/32/Small_AddCustomer.png"))); // NOI18N
        btn_Gui1.setText("Rút Tiền");
        btn_Gui1.setToolTipText("");
        btn_Gui1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        btn_Gui1.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btn_Gui1.setIconTextGap(40);
        btn_Gui1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_Gui1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btn_Them, javax.swing.GroupLayout.PREFERRED_SIZE, 171, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(btn_Gui, javax.swing.GroupLayout.PREFERRED_SIZE, 171, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(16, 16, 16)
                                .addComponent(btn_Gui1, javax.swing.GroupLayout.PREFERRED_SIZE, 171, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 993, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btn_Them, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(btn_Gui, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btn_Gui1, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 627, Short.MAX_VALUE))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jTable_CusMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable_CusMouseClicked
        // TODO add your handling code here:
        int index = jTable_Cus.getSelectedRow();
        this.txt_MaSo.setText(table.getValueAt(index, 0) + "");
        this.txt_TenChuSo.setText(table.getValueAt(index, 1) + "");
        this.txt_SoCMND.setText(table.getValueAt(index, 2) + "");
        this.txt_TenLoaiTietKiem.setText(table.getValueAt(index, 3) + "");
        this.txt_KyHan.setText(table.getValueAt(index, 4).toString().trim()+ "");
        this.txt_SoTienTrongTaiKhoan.setText(table.getValueAt(index, 5) + "");
        this.txt_TrangThaiSo.setText(table.getValueAt(index, 6) + "");
        this.JXNgayMoSo.setDate((Date) table.getValueAt(index, 7));
        
    }//GEN-LAST:event_jTable_CusMouseClicked

    private void btn_ThemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_ThemActionPerformed

        try {
            Unity.AddPanel(this, new JP_AddSavingBook());
        }catch (NotBoundException ex) {
            Logger.getLogger(JP_SavingBook.class.getName()).log(Level.SEVERE, null, ex);
        } catch (RemoteException ex) {
            Logger.getLogger(JP_SavingBook.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_btn_ThemActionPerformed

    private void btn_GuiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_GuiActionPerformed
        // TODO add your handling code here:
        try {
            Deposit_DTO info = new Deposit_DTO();
            info.setCustomerName(txt_TenChuSo.getText());
            info.setIDNumber(txt_SoCMND.getText());
            info.setBeneficiaryName(txt_TenChuSo.getText());
            info.setIDNumberBeneficiary(txt_SoCMND.getText());
            Unity.AddPanel(this, new JP_Deposit(info));
        }catch (NotBoundException ex) {
            Logger.getLogger(JP_SavingBook.class.getName()).log(Level.SEVERE, null, ex);
        } catch (RemoteException ex) {
            Logger.getLogger(JP_SavingBook.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_btn_GuiActionPerformed

    private void btn_Gui1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_Gui1ActionPerformed
        // TODO add your handling code here:
        try {
            WithDraw_DTO info = new WithDraw_DTO();
            info.setCustomerName(txt_TenChuSo.getText());
            info.setIDNumber(txt_SoCMND.getText());
            Unity.AddPanel(this, new JP_WithDraw(info));
        }catch (NotBoundException ex) {
            Logger.getLogger(JP_SavingBook.class.getName()).log(Level.SEVERE, null, ex);
        } catch (RemoteException ex) {
            Logger.getLogger(JP_SavingBook.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_btn_Gui1ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private org.jdesktop.swingx.JXDatePicker JXNgayMoSo;
    private javax.swing.JButton btn_Gui;
    private javax.swing.JButton btn_Gui1;
    private javax.swing.JButton btn_Them;
    private org.jdesktop.swingx.auth.JAASLoginService jAASLoginService1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable_Cus;
    private javax.swing.JTextField txt_KyHan;
    private javax.swing.JTextField txt_MaSo;
    private javax.swing.JTextField txt_SoCMND;
    private javax.swing.JTextField txt_SoTienTrongTaiKhoan;
    private javax.swing.JTextField txt_TenChuSo;
    private javax.swing.JTextField txt_TenLoaiTietKiem;
    private javax.swing.JTextField txt_TrangThaiSo;
    // End of variables declaration//GEN-END:variables

    /**
     * @return the registry
     */
    public Registry getRegistry() {
        return registry;
    }

    /**
     * @param registry the registry to set
     */
    public void setRegistry(Registry registry) {
        this.registry = registry;
    }

    /**
     * @return the rc
     */
    public IRemoteCustomer getRCustomer() {
        return rcustomer;
    }

    /**
     * @param rc the rc to set
     */
    public void setRCustomer(IRemoteCustomer rcustomer) {
        this.rcustomer = rcustomer;
    }
}
